<?php 
include 'db_functions/db_connect.php';
session_start();
if(isset($_SESSION['customer_username'])){
	$customer_username = $_SESSION['customer_username'];
}
else { echo "error: there is no active session"; }

/*fetch_row($customer_username);//function pou pairnei ws parametro to customer username
							  //trexei sql erwtima gia na parei ta stoixeia tou xristi
							  //kai pernaei se ena array oles tis plirofories pou iparxoun
							  //to onoma tou array einai $customer_info*/
							  
$qry_info="select * from customers where customer_username ='$customer_username'";

	$result_info=mysql_query($qry_info);
	$customer_info = mysql_fetch_array($result_info);
	
                              //grammes pou xrisimopoihsa gia na testarw an douleuei i selida

$customer_id=$customer_info['customer_id'];
//$orders_result=execute_order_query($customer_id);//function poy pairnei wx parametro to customer_id
								  //kai epistrefei ena result me oles tis orders tou sigkekrimenou customer
								  //to opoio xrisimopoioume argotera se fetch array
	
$qry_order="select * from orders where order_customers_id = '$customer_id'";

$orders_result=mysql_query($qry_order);	 //grammes pou xrisimopoihsa gia na testarw an douleuei i selida
	
?>
<HTML>
<HEAD>
<TITLE> <?php echo $customer_username; ?>'s Profile</TITLE>
 <script type="text/javascript">
function toggle5(showHideDiv, switchImgTag) {
        var ele = document.getElementById(showHideDiv);
        var imageEle = document.getElementById(switchImgTag);
        if(ele.style.display == "block") {
                ele.style.display = "none";
		imageEle.innerHTML = '<img src="img/plus.png">';
        }
        else {
                ele.style.display = "block";
                imageEle.innerHTML = '<img src="img/minus.png">';
        }
}	
 </script>
 
 
 <style type="text/css">
#info {
	position:fixed;
	top:30px;
	padding:15px;
	}
#orders {
	position:fixed;
	top:30px;	
	padding:15px;
	left:350px;
	}

</style>
 
 
</HEAD>
<BODY>

<DIV ID="info">
<h1>Customer Profile</h1>
<FORM ACTION="edit_profile.php" METHOD="POST">
<TABLE>
<TR><TD>Name<TD><INPUT TYPE="text" NAME="customer_name" VALUE="<?php echo $customer_info['customer_name']?>"></TR>
<TR><TD>Surname<TD><INPUT TYPE="text" NAME="customer_surname" VALUE="<?php echo $customer_info['customer_surname']?>"></TR>
<TR><TD>Address<TD><INPUT TYPE="text" NAME="customer_address" VALUE="<?php echo $customer_info['customer_address']?>"></TR>
<TR><TD>Floor<TD><INPUT TYPE="text" NAME="customer_floor" VALUE="<?php echo $customer_info['customer_floor']?>"></TR>
<TR><TD>Phone<TD><INPUT TYPE="text" NAME="customer_phone" VALUE="<?php echo $customer_info['customer_phone']?>"></TR>
<TR><TD>Username<TD><INPUT TYPE="text" NAME="customer_username" VALUE="<?php echo $customer_info['customer_username']?>" disabled="disabled"></TR>
<TR><TD>Password<TD><INPUT TYPE="password" NAME="customer_password" VALUE="<?php echo $customer_info['customer_password']?>"></TR>
</TABLE>
<?php if (empty($customer_info)) echo "There is no info for this username";?>
<INPUT TYPE="submit" VALUE="Edit Info">

</FORM>
</DIV>

<DIV ID="orders">

<h1>Previous Orders</h1>

<TABLE>
<TR><TD>Date & Time<TD></TR>
<?php	
	$i="1";
	settype($i, "string");
	$img_id="OrderImg";
	$order_id="Order";
	
	while($customer_order = mysql_fetch_array($orders_result)){ ?>
	<TR>
	<TD><a id="<?php echo $img_id.$i ?>" href="javascript:toggle5('<?php echo $order_id.$i ?>', '<?php echo $img_id.$i ?>');"><img src="img/plus.png"></a>
	<?php echo $customer_order['order_datetime']; ?>
	<TD></TR
	
<TR><TD><DIV id="<?php echo $order_id.$i ?>" style="display: none;">
<TABLE border="1" style="border: solid black; " class="orders" cellpadding="5">
<TR><TD>Date & Time<TD>Total<TD>Status</TR>
<TR>
<TD style="table-layout:fixed; width:150px;"><?php echo $customer_order['order_datetime']; ?>
<TD style="table-layout:fixed; width:50px;"><?php echo $customer_order['order_total']; ?>
<TD style="table-layout:fixed; width:80px;"><?php echo $customer_order['order_status']; ?>
</TR>
</TABLE>
</DIV></TR>
<?php 
settype($i, "integer");
$i=$i+1;
settype($i, "string"); } ?>
</TABLE>
</DIV>
<?php mysql_close($connection);//kleinei tin sindesi me tin vasi ?>
</BODY>
































</HTML>